@extends('/admin/Layout/layout')
@section('title','分类列表')
@section('content')
<div id="page-wrapper" style="min-height: 298px;">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">分类列表</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    模糊查询
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
                    <div class="dataTable_wrapper">
                        <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                        	<form action="" method='get' >
                        	<div class="row">
                        		<div class="col-sm-6">
                        			<div class="dataTables_length" id="dataTables-example_length">
                        				<label>显示&nbsp; 
                        				<select name="num" aria-controls="dataTables-example" class="form-control input-sm">
                                            <option @if($num==5) selected @endif value="5">5</option>
                                            <option @if($num==10) selected @endif value="10">10</option>
                                            <option @if($num==25) selected @endif value="25">25</option>
                                            <option @if($num==50) selected @endif value="50">50</option>
                        					<option @if($num==100) selected @endif value="100">100</option>
                        				</select>&nbsp; 条</label>
                        			</div>
                        		</div>
                        		<div class="col-sm-6">
	                        		<div id="dataTables-example_filter" class="dataTables_filter">
	                        		<label>
	                        			<span >搜索&nbsp;&nbsp;</span><input class="form-control input-sm" placeholder="" name='likes' value="{{$likes}}" aria-controls="dataTables-example" type="search">
	                        		</label>
	                        		<button class='btn btn-info'>查询</button>
	                        		</div>
	                        	</div>
	                        </div>
	                        </form>
	                    <div class="row">
	                      <div class="col-sm-12">
	                        <table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info">
                            <thead>
                            	<tr role="row">
                            		<th>分类ID</th>
                            		<th>分类名</th>
                            		<th>所属分类</th>
                            		<th>路径</th>
                            		<th>操作</th>
                            	</tr>
                            </thead>
                            <tbody>
                            @foreach($cates as $k=>$v )
                            <tr class="gradeA odd" role="row">
                                <td class="center id" style='text-align:center;' >{{$v->tid}}</td>
                                <td class="center" >{{$v->tname}}</td>
                                <td class="center" style='text-align:center;'>{{$v->xname}}</td>
                                <td class="center" >{{$v->path}}</td>
                                <td class="center" style='text-align:center;'>
									<button class="btn btn-info btn-outline btn-sm delete_btn"  >删除</button> &nbsp;&nbsp; 
									<a href="{{asset('/admin/cate/edit?id='.$v->tid)}}"><div class="btn btn-danger btn-outline btn-sm edit_btn" >修改</div></a>
                                </td>
                            </tr>
                            @endforeach
                            </tbody>
                        </table>
                      </div>
                    </div>
                    <div class="row">
                    	<div class="col-sm-6">
                    		<div class="dataTables_info" id="dataTables-example_info" role="status" aria-live="polite">
                    			
                    		</div>
                    	</div>
                    	<div class="col-sm-6">
                    		<div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
                    			<!-- 分页 -->
                                {!! $cates->appends($list)->render() !!}
                    		</div>
                    	</div>
                   	</div>
                   	</div>
                    </div>
                </div>
                <!-- /.panel-body -->
            </div>
            <!-- /.panel -->
        </div>
        <!-- /.col-lg-12 -->
    </div>
</div>
@endsection
@section('js')
	<script type="text/javascript">
	//删除的单击事件
	// alert($);
    
	$('.delete_btn').click(function()
	{
        if(!confirm('是否确认删除')){
            return;
        }
		$.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
		});
		var id = $(this).parents('tr').find('.id').html();
		// console.log(id);
		var btn = $(this);
		//ajax操作
		$.post("{{asset('/admin/cate/del')}}",{id:id},function(data){
			if(data==1){
				//正确
				alert('删除成功');
				btn.parents('tr').remove();
			}else if(data==2){
				//错误
				alert('有商品不能删除');
			}else{
                alert('有子分类不能删除');
            }
		})
	})
	</script>
@endsection